测试链接：https://leetcode.cn/problems/1fGaJU/description/
class Solution {
public:
    void Swap(vector<int>& nums, int left, int right)
    {
        int tmp = nums[left];
        nums[left] = nums[right];
        nums[right] = tmp;
    }

    void QuickSort1(vector<int>& nums, int left, int right)
    {
        if(left >= right) return;

        int begin = left;
        int end = right;

        int keyi = left;
        while(left < right)
        {
            while(left < right && nums[keyi] <= nums[right])
            {
                right--;
            }
            while(left < right && nums[left] <= nums[keyi])
            {
                left++;
            }

            Swap(nums, left, right);
        }
        Swap(nums, keyi, left);

        keyi = left;
        QuickSort1(nums,begin, keyi-1);
        QuickSort1(nums,keyi+1, end);
    }
    vector<vector<int>> threeSum(vector<int>& nums) {
        if(nums.size() < 3) return {};
        QuickSort1(nums, 0, nums.size()-1);
        for(auto & e : nums)
        {
            cout<<e;
        }
        // sort(nums.begin(),nums.end());
        int n = nums.size();
        vector<vector<int>> ans;
        for(int i = 0; i < n; i++)
        {
           while(i < n && i != 0 && nums[i] == nums[i-1] ) i++;
            int left = i+1;
            int right = n-1;
            while(left < right)
            {
                while(left < right && left != i+1  && nums[left] == nums[left-1]) left++;
                while(left < right && right != n-1  && nums[right] == nums[right + 1]) right--;
                if(left >= right) break;
                // cout<<nums[left]<< " " <<nums[right]<<endl;
                int sum = nums[i] + nums[left] + nums[right];
                if(sum == 0)
                {
                    ans.push_back({nums[i],nums[left],nums[right]});
                    left++;
                    right--;
                }
                else if(sum < 0)
                {
                    left++;
                }
                else
                {
                    right--;
                }
            }
        }

        return ans;

    }
};